package eu.jpereira.trainings.designpatterns.creational.builder.xml;

import eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBody;
import eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBodyBuilder;

public class XMLReportBodyBuilder implements ReportBodyBuilder
{
	XMLReportBody reportBody;
	boolean itemsAdded;
	
	public XMLReportBodyBuilder()
	{
		reportBody = new XMLReportBody();
		reportBody.putContent("<sale><customer>");
		itemsAdded = false;
	}
	@Override
	public ReportBodyBuilder setCustomerName(String customerName)
	{
		reportBody.putContent("<name>" + customerName + "</name>");
		return this;
	}

	@Override
	public ReportBodyBuilder setCustomerPhone(String phoneNumber)
	{
		reportBody.putContent("<phone>" + phoneNumber + "</phone>");
		reportBody.putContent("</customer>");
		return this;
	}

	@Override
	public ReportBodyBuilder withItems()
	{
		if(!itemsAdded)reportBody.putContent("<items>");
		else reportBody.putContent("</items></sale>");
		
		return this;
	}

	@Override
	public ReportBodyBuilder newItem(String name, int quantity, double price)
	{
		reportBody.putContent("<item><name>");
		reportBody.putContent(name);
		reportBody.putContent("</name><quantity>");
		reportBody.putContent(quantity);
		reportBody.putContent("</quantity><price>");
		reportBody.putContent(price);
		reportBody.putContent("</price></item>");
		
		return this;
	}

	@Override
	public ReportBody getReportBody()
	{
		return reportBody;
	}
	@Override
	public void setItemsAdded(boolean b)
	{
		itemsAdded = b;
	}

}
